package com.demo.spring.enable.async;

import java.util.concurrent.Executor;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

@Component
@EnableAsync(proxyTargetClass=true)
public class Student {

	@Bean
	public Executor asyncExecutor() {
		ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
		taskExecutor.setCorePoolSize(1);//线程池维护线程的最少数量
		taskExecutor.setMaxPoolSize(1);//线程池维护线程的最大数量
		taskExecutor.setQueueCapacity(10);//线程池所使用的缓冲队列
		taskExecutor.initialize();
		return taskExecutor;
	}

	@Async
	public void say() {
		System.out.println(Thread.currentThread().getName());
	}

	@Async
	public void say(String s) {
		System.out.println(Thread.currentThread().getName() + ", " + s);
	}

}
